import java.util.StringTokenizer;
import java.lang.reflect.Array;

public class LSType
{
	public static void convert(String line, int lineNumber, Assembled assembled)
	{
		int i = 1;
		int[] build;
		String temp = load_write(line, assembled);
		StringTokenizer tokenizer = new StringTokenizer(temp);
		
		build = new int[tokenizer.countTokens() + 2];
		build[0] = 3;//check this value later
		build[Array.getLength(build) - 1] = lineNumber;
		while(tokenizer.hasMoreTokens())
			build[i++] = Integer.parseInt(tokenizer.nextToken());
                if(build[1] == 32)
                {
                    tokenizer = new StringTokenizer(temp);
                    if(tokenizer.countTokens() == 3)
                    {
                        int n[] = new int[6];
                        n[0] = build[0];
                        n[1] = build[1];
                        n[2] = build[2];
                        n[3] = build[3];
                        n[4] = 0;
                        n[5] = build[4];
                        build = n;
                    }
                }
		assembled.addLine(build);
	}
	//creates the output data for load and store commands
	public static String load_write(String line, Assembled assembled)
	{
		String returnValue = new String();
		String command;
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		
		//String position;
		
		command = tokenizer.nextToken();
		command = command.trim();
		
		if(command.equals("lw"))
			returnValue = "35"; //"100011";
		else if(command.equals("sw"))
			returnValue = "43"; //"101011";
		else
			returnValue = "32"; //"100000";
		
		returnValue = returnValue + " " + Memory.memory(tokenizer.nextToken()) + " " + Memory.calculateMemoryLocation(assembled, tokenizer.nextToken());
		
		return returnValue;
	}
}